package com.doit.day03

object _04_集合之数组_稀奇古怪的方法 {
  def main(args: Array[String]): Unit = {
    val arr: Array[Int] = Array(1, 2, 3, 4)
    val arr1: Array[Int] = Array(10, 20, 30, 40)
    val arr2: Array[Int] = Array(10, 20, 30, 40)

    //我现在给你三个数组，我想吧三个数组合并成一个数组
    val ints4: Array[Int] = arr.++(arr1).++(arr2)
    val ints5: Array[Int] = arr ++ arr1  ++ arr2

    /*
    : 代表的就是原来的数组
     */
    //+ 添加一个元素
    val ints: Array[Int] = arr.:+(100)
    val ints1: Array[Int] = arr.+:(100)

    // ++ 添加一个集合
    val ints2: Array[Int] = arr.++(arr1)
    val ints3: Array[Int] = arr.++:(arr1)
    println(ints.mkString(","))//1,2,3,4,100
    println(ints1.mkString(","))//100,1,2,3,4
    println(ints2.mkString(","))//1,2,3,4,10,20,30,40
    println(ints3.mkString(","))//10,20,30,40,1,2,3,4



    //交集，并集，差集
    val arr10: Array[Int] = Array(1, 2, 3, 4,1,2)//3,4,1,2
    val arr20: Array[Int] = Array(1, 2, 30, 40)//1,2

    //差集
    val ints6: Array[Int] = arr10.diff(arr20)//3 4

    //并集
    val ints7: Array[Int] = arr10.union(arr20) //1,2,3,4,1,2,30,40
    val distinct: Array[Int] = ints7.distinct //1,2,3,4,30,40

    //交集
    val ints8: Array[Int] = arr10.intersect(arr20)//1 2

    println(ints6.mkString(","))
    println(ints7.mkString(","))
    println(ints8.mkString(","))
    println(distinct.mkString(","))
  }
}
